package com.java.demo.java;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradeWapPayResponse;

public class AliPayDemo {

    private final static String APP_ID = "2021004118622041";
    private final static String SERVER_URL = "https://openapi.alipay.com/gateway.do";
    private final static String FORMAT = "json";
    private final static String CHARSET = "UTF-8";
    private final static String PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHZo6u8aJ3G6LlrpwlYaDM25fQkziiqadcMncpWt5c4ilNXhf4N44+EsKVHx/JMLpDUX4AuyP5BMfo/5ALfjn6fv/gmvtcb+FrCZPWvi06fubtnEcX7rrPPXAz+xYeCmT/kBFqL1gM2JrhSYNJE6uV631USk/UhORYGO8tW+Ym+V9TA0odiRRET3aVpQlGP5SfA3FhnP9yzi/qRiEuBSfcVPghderyBX/h/HxZH7CQ5uo04Bvml1hUfcCJlxmiuNViN+oY+TP3RfpnGyisjx4iOOIfQR8KHtrRqOXyqio3rnIlK7vkm2sIBJZ3UM92hLlTM3s0vEJlHx9BbEySFSttAgMBAAECggEAIVvS+wmJuItzESHJFafjkuIZ39cBXpUrXo1CyjRdhwR/DGZ1dB03OsNAslnmo233e1Oi1NR6DCr0ltJKcuHHKVUd0aGb87bz60hK514hiuu4DoBalHJn5kvM/aU/6f6rLuYXQ8Bv5pZGMvJteEhGKGqhKPzVpiQlX2ese9YoBtTdnbbseT7YQKwa518Nj7wWMp7QfGEXerwEvcsQA/73/7/RFndZMBlU9sggGRf09ITAMGtKBoJJEqYAkj/tN71HnVO/ldKoXdm4u1JqxzOI3JU5EIBh2fFub2hSejlqv4HaSOj36qwLriOiQhMb8Gju8AWH/OP0JEv1zX1qIW8pgQKBgQDuPw/HRT/ehNAGnvXWqwGuLM2fbEY87f5j3YmeavBO9qUJ/on9ndoviBjROqoOtLIJuUT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0k3KrRooJhkGnixUi5GfLS2ai+wmQF+Lzwc4dL+X+zER9hmzi4VGDrsU0Oqok1zmn7fTqDfjpHbQFRsgnTp+z4Gz/YYyNkkSQN5L+NqkZXHQVd6Q67P3OTH0MZXpgMkyGuV+wIDAQAB";
    private final static String SIGN_TYPE = "RSA2";

    public static void main(String[] args) throws AlipayApiException {
        AlipayClient alipayClient = new DefaultAlipayClient(SERVER_URL, APP_ID, PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);
        AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
        request.putOtherTextParam("app_auth_token", "202309BB1838916ec0ca4493b4bbb412562fcX33");
        request.setNotifyUrl("");
        request.setReturnUrl("");
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no", "20210817010101004");
        bizContent.put("total_amount", 0.01);
        bizContent.put("subject", "测试商品");
        bizContent.put("product_code", "QUICK_WAP_WAY");
        bizContent.put("app_auth_token", "1111");
        request.setBizContent(bizContent.toString());
        AlipayTradeWapPayResponse response = alipayClient.pageExecute(request, "GET");
        if (response.isSuccess()) {
            System.out.println("调用成功");
            System.out.println(response.getBody());
        } else {
            System.out.println("调用失败");
        }
    }
}